
func() {
	echo "Usage:"
	echo "kafka_stress_test.sh"
	echo "-threads		num of thread"
	echo "-p		path of kafka test script"
	echo "-topic		topic name"
	echo "-num-records		total records"
	echo "-record-size		size(bytes) per records"
	echo "-producer-props		bootstrap servers list"
	exit -1
}


threads=""
path=""
topic=""
num_records=""
record_size=""
producer_props=""
startTime=`date +%Y%m%d-%H:%M:%S`
startTime_s=`date +%s`

ARGS=`getopt -o p: -l threads:,topic:,num-records:,record-size:,producer-props: -- "$@"`
eval set -- "${ARGS}"

while [ -n "$1" ]
do
    case "${1}" in
        -p) path=$2; shift 2;;
        --threads) threads=$2; shift 2;;
        --topic) topic=$2; shift 2;;
        --num-records) num_records=$2; shift 2;;
        --record-size) record_size=$2; shift 2;;
        --producer-props) producer_props=$2; shift 2;;
        --) break;;
        *) func;;
    esac
done

for i in `seq 1 $threads`
do
	{
		nohup $path --topic ${topic} --num-records ${num_records} --record-size ${record_size} --producer-props ${producer_props} --throughput -1 &> t${i}.nohup.log &
	}
done

echo "Waiting......"

wait

endTime=`date +%Y%m%d-%H:%M:%S`
endTime_s=`date +%s`

sumTime=$[ $endTime_s - $startTime_s ]

echo "Done! Total: $sumTime seconds"
